<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%-- 
    Document   : display
    Created on : Apr 16, 2015, 10:34:47 AM
    Author     : MasDar
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Using Form</title>
    </head>
    <body>
        <h1>Using Form</h1>
        <%
            Class.forName("org.postgresql.Driver");
            Connection conn = null;
            String userName = "neo";
            String password = "ne0_m07nf";
    // static String dbname = "NEO_MOEN";
            // static String serverip = "192.168.2.129";
            // static String serverip = "192.168.10.10";
            String dbname = "jsptest";
            //static String serverip = "127.0.0.1";
            String serverip = "127.0.0.1";
            String port = "5432";
            PreparedStatement preparedStatement;

            String firstName = request.getParameter("first");
            String lastName = request.getParameter("last");
            String gender = request.getParameter("gender");
            String email = request.getParameter("email");
            String dob = request.getParameter("birth");
            conn = DriverManager.getConnection(
                    "jdbc:postgresql://" + serverip + ":" + port + "/" + dbname + "?useUnicode=true&characterEncoding=UTF-8", userName,
                    password);

            String query = "INSERT INTO employee(name, lastname, gender, birth)VALUES ('" + firstName + "', '"
                    + lastName + "', '"
                    + gender + "', '"
                    + dob + "'); ";

            preparedStatement = conn.prepareStatement(query);
            preparedStatement.executeUpdate();
        %>
        <table border="1">

            <tbody>
                <tr>
                    <td>first Name:</td>
                    <td><%= firstName%></td>
                </tr>
                <tr>
                    <td>Second Name:</td>
                    <td><%= lastName%></td>
                </tr>
                <tr>
                    <td>address:</td>
                    <td><%= gender%></td>
                </tr>
                <tr>
                    <td>Gender:</td>
                    <td><%= email%></td>
                </tr>
                <tr>
                    <td>date of birth:</td>
                    <td><%= dob%></td>
                </tr>
            </tbody>
        </table>

    </body>
</html>
